package net.chasing.androidbaseconfig.view;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModel;

public abstract class BaseViewModel extends ViewModel implements LifecycleEventObserver {

    public BaseViewModel() {
        super();
    }

    public abstract void initResource();

    // Aty 解析传递的数据
    public void parseIntent(Intent intent) {
    }

    // Frg解析传递的数据
    public void parseBundle(Bundle bundle) {
    }

    @Override
    public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
        // onCreate也是可以监听到的
        if (event == Lifecycle.Event.ON_DESTROY) {
            releaseResource();
        }
    }

    public abstract void releaseResource();
}
